#include "AckNormal.h"

AckNormal::AckNormal(QWidget *parent) : QWidget(parent)
  ,udpSocket(NULL),timer(NULL)
{
    initClass();
    QString str("online");
    ba = str.toLatin1();
}

AckNormal::~AckNormal()
{
    udpSocket->close();
    udpSocket->disconnect();
    udpSocket->deleteLater();
    udpSocket = NULL;
    timer->stop();
    timer->disconnect();
    timer->deleteLater();
    timer = NULL;
}

void AckNormal::slotTimeout()
{
    udpSocket->writeDatagram(ba,QHostAddress::LocalHost,50002);
}

void AckNormal::initClass()
{
    udpSocket = new QUdpSocket(this);
    if(!udpSocket->bind(QHostAddress::LocalHost,50001,QAbstractSocket::ShareAddress)){
        QMessageBox::information(this,"Warning","绑定50001端口失败");
        return;
    }
    timer = new QTimer(this);
    connect(timer,&QTimer::timeout,this,&AckNormal::slotTimeout);
    timer->start(500);

}

